package com.green.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.green.system.common.DataGridView;
import com.green.system.domain.Notice;
import com.green.system.mapper.NoticeMapper;
import com.green.system.service.NoticeService;
import com.green.system.vo.NoticeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * Created with IntelliJ IDEA.
 * @Author: Green
 * @Date: 2021/10/22/16:29
 * @Description: 
 */


@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService{

    @Autowired
    private NoticeMapper noticeMapper ;

    @Override
    public DataGridView queryAllNotice(NoticeVo noticeVo) {
        IPage<Notice> page = new Page<>(noticeVo.getPage(),noticeVo.getLimit());

        if(noticeVo.getTitle() == null){
            noticeVo.setTitle("");
        }
        if (noticeVo.getOpername() == null){
            noticeVo.setOpername("");
        }

        QueryWrapper<Notice> qw = new QueryWrapper<>();
        qw.like(StringUtils.isBlank(noticeVo.getTitle()),"title",noticeVo.getTitle());
        qw.like(StringUtils.isBlank(noticeVo.getOpername()),"opername",noticeVo.getOpername());
        qw.ge(noticeVo.getStartTime()!=null,"createtime",noticeVo.getStartTime());
        qw.le(noticeVo.getEndTime()!=null,"createtime",noticeVo.getEndTime());
        qw.orderByDesc("createtime");

        this.noticeMapper.selectPage(page,qw);

        return new DataGridView(page.getTotal(),page.getRecords());
    }
}
